package com.finesys.backend.api.model.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.finesys.backend.common.model.user.UserModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: 业务系统返回的用户信息</p>
 * <p>Description: </p>
 * <p>Copyright: CopyRight (c) 2020-2035</p>
 * <p>Company: finesys Co. LTD.</p>
 * <p>Author: lehoon</p>
 * <p>Date: 2021/1/29 17:35</p>
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class UserInfoVo implements Serializable {
    private String id;
    private String username;
    private String name;
    @JsonIgnore
    private String phone;
    private String introduction;
    //role node list
    private List<String> roles = new ArrayList<String>();

    public void pushRole(String roleName) {
        roles.add(roleName);
    }

    /**通过userModel生成vo*/
    public static UserInfoVo fromUserModel(UserModel userModel) {
        UserInfoVo userInfoVo = new UserInfoVo();
        userInfoVo.setId(userModel.getId());
        userInfoVo.setName(userModel.getName());
        userInfoVo.setUsername(userModel.getUsername());
        userInfoVo.pushRole(userModel.getRolename());
        userInfoVo.setIntroduction("丰汇部署运维系统管理员");
        if ("admin".equals(userModel.getUsername())) {
            userInfoVo.pushRole("super");
        }
        return userInfoVo;
    }
}
